﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClienteWinMGI.Logica;
using ComunesMGI.DataTypes;
using ComunesMGI.Mensajes;

namespace ClienteWinMGI.Presentacion
{
    public partial class AltaCliente : Form
    {
        public AltaCliente()
        {
            InitializeComponent();
            clearValidator();
        }
        private void clearValidator()
        {
            imgValidator.Visible = false;
            lblValidator.Visible = false;
        }

        private void showValidator(string textoValidator)
        {
            imgValidator.Visible = true;
            lblValidator.Visible = true;
            lblValidator.Text = textoValidator;
        }
        private void btnAgregarCliente_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNomCli.Text != "")
                {
                    clearValidator();
                    IClientes ic = LogicaFactory.getInstance().getIClientes();
                    DataCliente dataCli = new DataCliente(txtNomCli.Text);
                    ic.AddCliente(dataCli);
                    MsgNotificacion notif = new MsgNotificacion("Alta exitosa", "Alta de cliente exitosa", "Se ha dado de alta el cliente de nombre " + dataCli.Nombre+ " en forma exitosa");
                    notif.ShowDialog();
                }
                else
                {
                    showValidator("Debe ingresar nombre de cliente");
                }
            }
            catch (Exception ex)
            {
                MsgError err = new MsgError("Error", "", ex.Message);
                err.ShowDialog();
            }

        }

        private void txtNomCli_TextChanged(object sender, EventArgs e)
        {
            clearValidator();
        }

        private void btnCancelarCliente_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
